// -----------------------------------------------------------------------------
// quick 8
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// functions
// -----------------------------------------------------------------------------
function changeNumArr(){
  var reArr = [0,''];
  var reNullArr = [0,''];
  var str = '';
  var oChkP = $('#tblQPG01 input:checkbox:checked');
  var oChkG = $('#tblQPG02 input:checkbox:checked');
  var oChkT = $('#tblQPG03 input:checkbox:checked');
  var oChkPL = oChkP.length;
  var oChkGL = oChkG.length;
  var oChkTL = oChkT.length;
  var i = 0; var j = 0; var k = 0; var n = 0; var p = ''; var strArr = ''; var eachNum = $('#eachNum').val() - 0;
  str = '<tr>';
  for(i = 0; i < oChkPL ; i++){
    p = oChkP[i].value;
    for(j = 0; j < oChkGL ; j++){
      if(n > 0 && n % eachNum == 0){ str += '</tr><tr>'; }  // count tr
      n++;
      str += '<td class="onNum">' + getBetNumName(p, oChkG[j].value) + '</td>';
    }
  }
  for(k = 0; k < oChkTL ; k++){
    if(n > 0 && n % eachNum == 0){ str += '</tr><tr>'; }  // count tr
    n++;
    str += '<td class="onNum">' + getBetNumName(0, oChkT[k].value) + '</td>';
  }
  str += '</tr>';
  if(n > 0){ return [n, str]; }
  else{ return reNullArr; }
}

$(function(){

  // quick checkbox
  $("#slcChgQuickPG").click(function(){
    location.replace( _reladURL + '&qFast=0');
  });

  $(".tblQPG input:checkbox").click(function(){
    $(this).parent('label').toggleClass("noClk");
  }); 
  
  // proc quick data
  $("#btnProcData").click(function(){
    $(this).attr("disabled", "disabled");
    var strArr = changeNumArr();
    var l = strArr[0];
    $("#totalNumCount").text(0);
    if(l){
      $("#tbdShowNumber").html(strArr[1]);
      $("#tbdShowNumber td").click(function(){
        $(this).toggleClass("onNum");
        var onNumLen = $("#tbdShowNumber td.onNum").length;
        var sendMonNumTotal = $('#setMomney').val() * 1 * onNumLen;
        $("#sendNumTotal").text(onNumLen);
        $("#sendMonNumTotal").text(sendMonNumTotal);
      });
      $("#totalNumCount").text(l);
      $("#sendNumTotal").text(l);
      $("#sendMonNumTotal").text(($('#setMomney').val() * 1 * $("#tbdShowNumber td.onNum").length));
    }else{
      $("#tbdShowNumber").html('<tr><td colspan="4" class="c2"> -- </td></tr>');
       $("#sendNumTotal").text('0');
       $("#sendMonNumTotal").text('0');
    }
    $(this).removeAttr("disabled");
  }); 
  
  // clear
  $("input:reset").click(function(){
    $(".tblQPG label").removeClass('noClk');   
  }); 
  
  // btnCancel
  $("#btnCancel").click(function(){
    $("#tbdShowNumber").empty();
    $("#sendNumTotal").text('0');
    $("#sendMonNumTotal").text('0');
    $("#setMomney").val('0');
    $("#totalNumCount").text('0');
  });
  
  // btnSent    
  $("#btnSent").click(function(){
    var setMon = $('#setMomney').val(); 
    if(setMon <  _betmin){ alert(_err01); $('#setMomney').focus(); return false; }
    var l = $("#tbdShowNumber td.onNum").length;
    if(l < 1){ alert(_err02); return false; }
    $(this).attr('disabled');
    var str = '';
    $("#tbdShowNumber td.onNum input:hidden").val(setMon);
    $(this).attr("disabled", "disabled");
    $("input#disk").attr("value",$("select#slcDisk option:selected").val());
    $("#frmSubData").submit();
  });
  
  // btn change face to number
  $("#chgFace2Num").click(function(){
    $(".autoLab2 input").removeAttr('checked').parent('label').removeClass('noClk');
    var oChkG = $('#tblQPG02 input:checkbox:checked');
    var oChkGL = oChkG.length;
    var i = 0;  
    for(i = 0; i < oChkGL; i++){ getFace2Num(oChkG[i].value); oChkG[i].click(); }
  });
  
  // time of now
  $("span#showNowTime").showNowTime();
  
});                                                                                                                                                                        

// get the bet name of number
function getBetNumName(pStr, gStr){
  var uTitle = new Array();uTitle['0_1'] = '球号一';uTitle['0_2'] = '球号二';uTitle['0_3'] = '球号三';uTitle['0_4'] = '球号四';uTitle['0_5'] = '球号五';uTitle['0_6'] = '球号六';uTitle['0_7'] = '球号七';uTitle['0_8'] = '球号八';uTitle['1_1'] = '球号一单双';uTitle['1_2'] = '球号二单双';uTitle['1_3'] = '球号三单双';uTitle['1_4'] = '球号四单双';uTitle['1_5'] = '球号五单双';uTitle['1_6'] = '球号六单双';uTitle['1_7'] = '球号七单双';uTitle['1_8'] = '球号八单双';uTitle['2_1'] = '球号一大小';uTitle['2_2'] = '球号二大小';uTitle['2_3'] = '球号三大小';uTitle['2_4'] = '球号四大小';uTitle['2_5'] = '球号五大小';uTitle['2_6'] = '球号六大小';uTitle['2_7'] = '球号七大小';uTitle['2_8'] = '球号八大小';uTitle['3_1'] = '球号一尾大小';uTitle['3_2'] = '球号二尾大小';uTitle['3_3'] = '球号三尾大小';uTitle['3_4'] = '球号四尾大小';uTitle['3_5'] = '球号五尾大小';uTitle['3_6'] = '球号六尾大小';uTitle['3_7'] = '球号七尾大小';uTitle['3_8'] = '球号八尾大小';uTitle['4_1'] = '球号一合单双';uTitle['4_2'] = '球号二合单双';uTitle['4_3'] = '球号三合单双';uTitle['4_4'] = '球号四合单双';uTitle['4_5'] = '球号五合单双';uTitle['4_6'] = '球号六合单双';uTitle['4_7'] = '球号七合单双';uTitle['4_8'] = '球号八合单双';uTitle['5_1'] = '球号一中发白';uTitle['5_2'] = '球号二中发白';uTitle['5_3'] = '球号三中发白';uTitle['5_4'] = '球号四中发白';uTitle['5_5'] = '球号五中发白';uTitle['5_6'] = '球号六中发白';uTitle['5_7'] = '球号七中发白';uTitle['5_8'] = '球号八中发白';uTitle['6_1'] = '球号一方位';uTitle['6_2'] = '球号二方位';uTitle['6_3'] = '球号三方位';uTitle['6_4'] = '球号四方位';uTitle['6_5'] = '球号五方位';uTitle['6_6'] = '球号六方位';uTitle['6_7'] = '球号七方位';uTitle['6_8'] = '球号八方位';uTitle['7_0'] = '总单双';uTitle['8_0'] = '总大小';uTitle['9_0'] = '总尾大小'; uTitle['18_0'] = '龙虎';
  var titleStrArr = gStr.split("_");  if(titleStrArr.length != 2){ return '- error -'; } var bettype = titleStrArr[0];  var subid = pStr;  var num = titleStrArr[1]; var titleIdx = bettype + '_' + subid; var titleStr = '<input type="hidden" name="b_' + subid + '_' + bettype + '_' + num + '" value="" />【' + uTitle[titleIdx] + '】';  switch(bettype){  case '0':  return titleStr + num;  break;  case '1':  var tempArr = [ '', '单','双'];  return titleStr + tempArr[num];  break;  case '2':  var tempArr = [ '', '大','小'];  return titleStr + tempArr[num];  break;  case '3':  var tempArr = [ '', '尾大','尾小'];  return titleStr + tempArr[num];  break;  case '4':  var tempArr = ['', '合单','合双'];  return titleStr + tempArr[num];  break;  case '5':  var tempArr = [ '', '中','发','白'];  return titleStr + tempArr[num];  break;  case '6':  var tempArr = [ '','东','南','西','北'];  return titleStr + tempArr[num];  break;  case '7':  var tempArr = ['', '总单','总双'];  return titleStr + tempArr[num];  break;  case '8':  var tempArr = ['', '总大','总小'];  return titleStr + tempArr[num];  break;  case '9':  var tempArr = ['', '总尾大','总尾小'];  return titleStr + tempArr[num];  break;  case '18':  var tempArr = ['', '龙','虎'];  return titleStr + tempArr[num];  break;  }  return '-null-';
}; 

// filter the num arr
function getFace2Num(fTypeStr){
  var myBtnId = fTypeStr.split("_");
  if(myBtnId.length != 2 ){ return ;}
  var i = 0;
  var oObj = $(".autoLab2 input:not(:checked)");
  var attVal1 = '';
  var attVal2 = '';
  var sNumIdx = 1;
  switch(myBtnId[0]){
    case '1':
      var typeCharNum = myBtnId[1] % 2;
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx];
          //if(sNum == 21){ return false;}
          return (sNum % 2 == typeCharNum);
      }).click();
      break;
    case '2':
      var typeCharNum = myBtnId[1] -1;
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx];
          //if(sNum == 21){ return false;}
          if(typeCharNum){ return (sNum < 11); }
          else{ return (sNum > 10); }
      }).click();
      break;
    case '3':
      var typeCharNum = myBtnId[1] -1;
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx].charAt(1);
          //if(sNum == 21){ return false;}
          if(typeCharNum){ return (sNum < 5); }
          else{ return (sNum > 4); }
      }).click();
      break;  
    case '4':
      var typeCharNum = myBtnId[1] % 2;
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx];
          //if(sNum == 21){ return false;}
          var sNum_1 = sNum.charAt(0) - 0;
          var sNum_2 = sNum.charAt(1) - 0;
          return (( sNum_1 + sNum_2 ) % 2 == typeCharNum);
      }).click();
      break;
    case '5':
      var typeCharNum = myBtnId[1] - 1;
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx];
          var subNum = 0;
          if((sNum % 7) == 0){ subNum = 1;}
          if(typeCharNum == (Math.floor(sNum / 7) - subNum)){ return true;}
          else { return false; }
      }).click();
      break;
    case '6':
      var typeCharNum = myBtnId[1];
      if(typeCharNum == 4){ typeCharNum = 0; }
      oObj.filter(function(idx, ele){
          var myN = $(ele).val().split("_");
          var sNum = myN[sNumIdx];
          if(typeCharNum == (sNum % 4)){ return true;}
          else { return false; }
      }).click();
      break;   
  }
}

$.fn.showNowTime = function(){
  var thisObj = $(this);
  var str = "时间：<b>"+ _now.getDate() +"【"+( _now.getHours() )+":"+( _now.getMinutes())+":"+( _now.getSeconds())+"】</b>";
  if(_timestap >=0){
    timediff = _timestap;
    days = Math.floor(timediff / (86400));   // 60 * 60 * 24
  	timediff -= days * (86400);
  	hours = Math.floor(timediff / (3600));  // 60 * 60
  	timediff -= hours * (3600);	
  	mins = Math.floor(timediff / (60));
  	timediff -= mins * (60);	
  	secs = Math.floor(timediff);
    str += "，距离【第" + _round + "期】截止下注时间还有 ";
    if (days > 0 ) str += "<b>" + days + "</b> 天 ";
    if (hours > 0) str += "<b>" + hours + "</b> 小时 ";
    if (mins > 0) str += "<b>" + mins + "</b> 分钟 ";
    str += "<b>" + secs + "</b> 秒 ";
    _timestap-=1;
  }else{
    str += "<font color=red><b>【" + _gametypeStr + "】已经截止下注！</b></font>";
    setTimeout('parent.mainFrame.location.reload()',1000);
    setTimeout('parent.leftFrame.location.reload()',1000);
  }
  $(this).html(str);
  _now.setTime(_now.getTime() + 1000);
  setTimeout(function(){$(thisObj).showNowTime();},1000);
}; 
